package com.mumu.jetpackdemo.page;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.arch.paging.PagedList;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.mumu.jetpackdemo.R;

public class DemoPagingActivity extends AppCompatActivity implements View.OnClickListener {

    private RecyclerView helloRv;
    private My2ViewModel mModel;
    private My2Adapter mAdapter;

    public static void startPaging(Context context) {
        context.startActivity(new Intent(context, DemoPagingActivity.class));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_paging);

        helloRv = (RecyclerView) findViewById(R.id.hello_rv);
        findViewById(R.id.button4).setOnClickListener(this);


        helloRv.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new My2Adapter();
        helloRv.setAdapter(mAdapter);

        mModel = ViewModelProviders.of(this).get(My2ViewModel.class);
        mModel.getLive().observe(this, new Observer<PagedList<String>>() {
            @Override
            public void onChanged(@Nullable PagedList<String> strings) {
                mAdapter.submitList(strings);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button4:

                break;
        }
    }
}
